package cn.jxwazx.sheinspringboot.controller;

import cn.jxwazx.sheinspringboot.entity.R;
import cn.jxwazx.sheinspringboot.entity.param.UserLoginParam;
import cn.jxwazx.sheinspringboot.entity.vo.UserPageVo;
import cn.jxwazx.sheinspringboot.holder.UserHolder;
import cn.jxwazx.sheinspringboot.service.UserInfoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

/**
 * @author root
 * @date 2023年11月09日 下午1:48
 * @description believe in yourself
 */
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class AdminUserController {

    private final UserInfoService userInfoService;




    /**
     * 用户登录
     *
     * @return
     */
    @PostMapping("/login")
    public Object login(@RequestBody UserLoginParam userInfo) {
        String token = userInfoService.login(userInfo);
        return R.success(token);
    }




    /**
     * 获取当前用户信息
     * @return {@link Object}
     */
    @GetMapping("/info")
    public Object info(){
        Long id = UserHolder.getId();
        UserPageVo userPageVo = userInfoService.detail(id);
        return R.success(userPageVo);
    }
}
